/**
 * 功能描述
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");

    //assets
    var template = require("./assets/tpl/returnvisit_main.tpl");
    require("./assets/css/returnvisit_main.css");
    
    var store =require("store");
	var activeUser = store.get("user");	

    //business

    //component
    var intentionregisterSubnavComp = require("./component/returnvisitSubnavComp");
    var intentionregisterGridComp = require("./component/returnvisitGridComp");
    var tabComp = require("./component/tabComp");
    var questionnaireProfileComp = require("./component/questionnaireProfileComp");
    var visitFormComp = require("./component/visitFormComp");
    var recordGridComp = require("./component/recordGridComp");
    var intentionregister_Props = require("./constant/returnvisit_Props");
    //constant
    
    //handler
    var IntentionRegisterSubnav_Events = require("./handler/ReturnvisitSubnav_Events");
    var IntentionRegister_Events=require("./handler/Returnvisit_Events")
    
    var visitway_main = ELView.extend({
        attrs: {
            template: template
        },
        events:{
			"click .returnVisit":function(e){
				var grid=this.get("grid");
				var index=grid.getIndex(e.target);
				var data=grid.getData(index);
				var pkIntentionRegister=$(e.target).attr("id");
				IntentionRegister_Events.showReturnVisit(this,null);
			},
			"change .J-form-visitRecord-select-product":function(e){
				IntentionRegister_Events.changeProduct(this,null);
			},
	        "blur .J-form-visitRecord-date-birthday":function(e){
	        	IntentionRegister_Events.changeBirthday(this,this.get("form").getValue("birthday"));
			}
        },
        initComponent: function (params, widget) {
        	intentionregisterSubnavComp.initComponent(params, widget); 
        	intentionregisterGridComp.initComponent(params, widget); 
        	tabComp.initComponent(params, widget); 
        	questionnaireProfileComp.initComponent(params, widget); 
        	visitFormComp.initComponent(params, widget); 
        	recordGridComp.initComponent(params, widget); 
        
        },
        skip: function(params, widget){
        	var status =  params.status;
        	var product = params.product;
        	var productType = params.productType;
        	
        	var refreshData = {};
        	
        	if(status == "Contract"){
        		refreshData = {
                		"productType.pkProductType":productType.key,
                		"status":status,
        				fetchProperties:intentionregister_Props.gridFetchProperties
            	}
        		this.get("grid").refresh(refreshData);
        	}else{
        		refreshData = {
                		"productType.pkProductType":productType.key,
                		"intention":status,
        				fetchProperties:intentionregister_Props.gridFetchProperties
            	}
        		this.get("grid").refresh(refreshData);
        	}
        	widget.set("refreshData", refreshData);
        	this.get("subnav").hide(["visitTime","status","intention","productType","product","save"]).show(["search"]);
        	this.show([".J-grid"]);
        },
        afterInitComponent: function (params, widget) {
        	widget.get("subnav").load("product",{
                callback : function(data){
                	IntentionRegisterSubnav_Events.changeType(widget);
                }
            });
        }
    });

    module.exports = visitway_main;
});
